import Cookie from 'js-cookie';
import store from '@/store';
import router from '@/router';

const TOKEN_KEY = 'token';

export const getToken = () => Cookie.get(TOKEN_KEY);

export const setToken = val => Cookie.set(TOKEN_KEY, val, {
  expires: 1000*24*60*60*1000
});

export const clearToken = () => Cookie.remove(TOKEN_KEY);

export const getHeaders = () => ({
  Authorization: 'Bearer ' + store.getters.token
});

export const redirectToLogin = () => {
  clearToken();
  router.replace('/view/login');
}


const USER_KEY = 'userid';
export const setUserId = val => Cookie.set(USER_KEY, val);
export const getUserId = () => Cookie.get(USER_KEY);

export const setCookies = (key, val) => {
  Cookie.set(key, val);
}

export const getCookies = (key) => {
  let a = Cookie.get(key);
  return a
}
